#!/afs/nd.edu/user15/pbui/pub/weaver/bin/weaver
#Programmer: Rory Carmichael
#Program: shuffle_genes.py
#Purpose: Weaver script to distribute gene shuffling 
#Usage: shuffle_genes.py <method> <permutations> <ldist_dir>

import shlex, subprocess
from weaver.nest import Nest
from weaver.function import SimpleFunction, PythonFunction, Function
from weaver.dataset import Chunk
from array import array
import re
import sys

def usage(): 
	print "shuffle_genes.py <cumulative?(y/n/a)> <method> <permutations> <ldist_dir>\n"

if len(CurrentScript().arguments) != 4:
	usage()
	sys.exit(2)

shuffle = Function('rc-shuffle-clust.pl', cmd_format = "{executable} %s %s %s {inputs} > {outputs}" % (CurrentScript().arguments[0],CurrentScript().arguments[1],CurrentScript().arguments[2])) 

ldistdir = CurrentScript().arguments[3] + "/*.ldist_spliced"
answers = Map(shuffle, Glob(ldistdir), '{basename_woext}.prob.txt')
